package com.me.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.me.enums.ScreenEnum;
import com.me.helper.MySkin;
import com.me.helper.PreferencesData;
import com.me.memorytest.MainMemoryTest;
import com.me.utils.PackerUtils;

public class LoadingScreen extends BaseScreen {

	AssetManager manager = new AssetManager();

	@Override
	public void show() {
		super.show();
		Texture.setEnforcePotImages(false);
		PreferencesData.setCategory(1);
		PackerUtils.initPath();

		manager.load(PackerUtils.PATH_TEXTUREPACKER, TextureAtlas.class);
	}

	@Override
	public void render(float arg0) {
		super.render(arg0);

		manager.update();
		float fprogress = manager.getProgress();
		if (fprogress >= 1) {
			MainMemoryTest.mySkin = new MySkin();
			MainMemoryTest.atlas = new TextureAtlas(
					Gdx.files.internal(PackerUtils.PATH_TEXTUREPACKER));
			MainMemoryTest.getScreenManager().createScreen(
					ScreenEnum.MENU_SCREEN);
			MainMemoryTest.getScreenManager().getScreen().show();
		}
	}

	@Override
	public void resize(int width, int height) {
		super.resize(width, height);
		width = 1280 * width / height;
		height = 720;
		BaseScreen.stage.setViewport(width, height, false);
	}
}
